<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<jsp:include page="/includes/top.jsp"></jsp:include>
<div class="page-header">
	<h1></h1>
</div>
<!-- /.page-header -->
<div class="row">
	<div class="col-xs-12">
		<form class="form-horizontal" id="uiform">
			<ul class="nav nav-tabs">
				<li class="active"><a href="#tabs-1" data-toggle="tab">基本信息</a></li>
				<li><a href="#tabs-2" data-toggle="tab">更多</a></li>
			</ul>
			<div class="tab-content">
				<div id="tabs-1" class="tab-pane fade in active">
					<div style="display: none">
						<input type="hidden" name="projects.projectId" id="hidUserId"
							value="${projects.projectId}" />
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">项目名称</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectName"
									value="${projects.projectName}" class="form-control"
									placeholder="项目名称" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">项目简称</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectShortName"
									value="${projects.projectShortName}" class="form-control"
									placeholder="项目简称" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">公司名称</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<s:select cssClass="form-control" id="company"
									name="projects.projectCompany" list="#clist "
									listValue="companyName" listKey="companyId"
									value="projects.projectCompany"></s:select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">项目负责人</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<s:select cssClass="form-control" id="users"
									name="projects.projectOwner" list="#ulist "
									listValue="sysUserinfo.userinfoTruename" listKey="userId"
									value="projects.projectOwner"></s:select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">主导部门</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<s:select cssClass="form-control" id="depart"
									name="projects.projectDepartments" list="#dlist "
									listValue="departmentName" listKey="departmentId"
									value="projects.projectDepartments"></s:select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">开始日期</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<div class="input-group">
									<input type="text" name="projects.projectStartDate"
										id="projectStartDate" value="${projects.projectStartDate}"
										class="form-control date-picker" /> <span
										class="input-group-addon"> <i
										class="icon-calendar bigger-110"></i>
									</span>
								</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">预计完成日期</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<div class="input-group">
									<input type="text" name="projects.projectEndDate"
										id="projectEndDate" value="${projects.projectEndDate}"
										class="form-control date-picker" /> <span
										class="input-group-addon"> <i
										class="icon-calendar bigger-110"></i>
									</span>
								</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">项目类型</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<s:select cssClass="form-control" name="projects.projectType"
									list="#tlist " listValue="projectTypeName"
									listKey="projectTypeId" value="projects.projectType"></s:select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">状态</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<s:select cssClass="form-control" name="projects.projectStatus"
									list="#slist " listValue="projectStatusName"
									listKey="projectStatusId" value="projects.projectStatus"></s:select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">优先级</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<s:select cssClass="form-control"
									name="projects.projectPriority" list="#plist "
									listValue="projectPriorityName" listKey="projectPriorityId"
									value="projects.projectPriority"></s:select>
							</div>
						</div>
					</div>
				</div>
				<div id="tabs-2" class="tab-pane fade">
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">预算</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectTargetBudget"
									value="${projects.projectTargetBudget}"
									id="projectTargetBudget" class="form-control" placeholder="预算" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">实际支出</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectActualBudget"
									value="${projects.projectActualBudget}"
									id="projectActualBudget" class="form-control"
									placeholder="实际支出" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">样例URL</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectDemoUrl"
									value="${projects.projectDemoUrl}" id="projectDemoUrl"
									class="form-control" placeholder="样例URL" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">项目网址(URL)</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectUrl" id="projectUrl"
									value="${projects.projectUrl}" class="form-control"
									placeholder="项目网址(URL)" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">完成百分比</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<input type="text" name="projects.projectPercentComplete"
									value="${projects.projectPercentComplete}" id="ppc"
									class="form-control" value="0" placeholder="完成百分比" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right">描述</label>
						<div class="col-sm-4">
							<div class="clearfix input-icon input-icon-right">
								<textarea class="form-control"
									name="projects.projectDescription" id="projectDescription"
									placeholder="描述" rows="6">${projects.projectDescription}</textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div class="col-xs-12">
		<div class="clearfix form-actions">
			<div class="col-md-offset-3 col-md-9">
				<button class="btn btn-info" type="button" id="save">
					<i class="icon-ok"></i> 保存
				</button>

				&nbsp; &nbsp; &nbsp;
				<button class="btn" type="reset" id="back">
					<i class="icon-undo"></i> 取消
				</button>
			</div>
		</div>
	</div>
</div>

<!-- /.col -->
<jsp:include page="/includes/bottom.jsp"></jsp:include>

<script type="text/javascript">
	var uid = getQueryString("projects.projectId");

	function savafrom(url) {
		$("#save").click(function() {
			$("#uiform").bootstrapValidator("validate");
			if ($("#uiform").data("bootstrapValidator").isValid()) {
				var dataMap = $("#uiform").serializeArray();
				$.ajax({
					type : "post",
					url : url,
					data : dataMap,
					dataType : "json",
					success : function(data) {
						window.open("Projects/projectslist.jsp?m="
								+ mid, "_self");
					}
				});
			}
		});
	}

	$(document).ready(function() {
		$('.date-picker').datetimepicker({
			lang : 'ch',
			format : 'Y-m-d H:m:s'
		}).next().on("click", function() {
			$(this).prev().focus();
		});

		if (uid != null && uid != "") {
			savafrom("editprojects");
		} else {
			savafrom("addprojects");
		}
		if($("#ppc").val()=="")$("#ppc").val(0);
		$("#company").change(function() {
			setselectval("depart","departall","departmentId","departmentName",{cid:$(this).val()});	
			setselectval("users","userall","userId","userinfoTruename",{cid:$(this).val()});				
		});
		$("#back").click(function() {
			window.history.back();
		});
		
		validator();
		$("#projectStartDate").on("change show", function() {
            $("#uiform").bootstrapValidator("revalidateField", "projects.projectStartDate");
        });
        $("#projectEndDate").on("change show", function() {
            $("#uiform").bootstrapValidator("revalidateField", "projects.projectEndDate");
        });
	});

	function validator() {
		$("#uiform").bootstrapValidator({
			feedbackIcons : {
				valid : 'icon-ok-sign',
				invalid : 'icon-remove-sign',
				validating : 'icon-refresh'
			},
			fields : {
				'projects.projectName' : {
					validators : {
						notEmpty : {
							message : '项目名称，不能为空！'
						}
					}
				},
				'projects.projectCompany' : {
					validators : {
						notEmpty : {
							message : '公司名称，不能为空！'
						}
					}
				},
				'projects.projectOwner' : {
					validators : {
						notEmpty : {
							message : '项目负责人，不能为空！'
						}
					}
				},
				'projects.projectDepartments' : {
					validators : {
						notEmpty : {
							message : '主导部门，不能为空！'
						}
					}
				},
				'projects.projectStartDate' : {
					validators : {
						notEmpty : {
							message : '开始日期，不能为空！'
						}
					}
				},
				'projects.projectEndDate' : {
					validators : {
						notEmpty : {
							message : '预计结束日期，不能为空！'
						}
					}
				},
				'projects.projectTargetBudget' : {
					validators : {
						regexp: {
	                        regexp: /^[0-9_\.]+$/,
	                        message: '只能输入数字'
	                    }
					}
				},
				'projects.projectActualBudget' : {
					validators : {
						regexp: {
	                        regexp: /^[0-9_\.]+$/,
	                        message: '只能输入数字'
	                    }
					}
				},
				'projects.projectPercentComplete' : {
					validators : {
						regexp: {
	                        regexp: /^[0-9_\.]+$/,
	                        message: '只能输入数字'
	                    },
						greaterThan : {
							value : 0,
							inclusive : true,
							message : '最小值0'
						},
						lessThan : {
							value : 100,
							inclusive : true,
							message : '最大值100'
						}
					}
				},
	            'projects.projectDemoUrl': {
	                validators: {
	                    uri: {
	                        allowLocal: true,
	                        message: '请输入正确 URL'
	                    }
	                }
	            },
	            'projects.projectUrl': {
	                validators: {
	                    uri: {
	                        allowLocal: false,
	                        message: '请输入正确 URL'
	                    }
	                }
	            }
			}
		});
	}

	
</script>